Two urgent cake orders came to Byteasar's confectionery.
As we all know, cakes have layers.
The confectionery offers
different kinds of layers
and each cake contains exactly one layer of each kind.
A cake order specifies a sequence in which the layers are to be placed.
Byteasar hires
confectioners; the
-th confectioner
(for
) can prepare only a layer of the
-th kind.
Each confectioner places his layer in a single minute
(during that time he or she can work on a single cake only).
Layers of a cake are to be placed one by one,
however two cakes can be processed in parallel.
How much time will it take to fulfill the two given cake orders,
assuming that the cakes are produced in an optimal manner?
The first line of input contains a single integer
(
).
Two lines follow containing a description of the first and the second
cake order respectively.
Each cake order is a sequence of
pairwise distinct integers
of value between
and
,
describing the subsequent layers of the ordered cake
starting from the topmost layer.
The first and only line of output should contain a single integer: the number of minutes needed to produce the two ordered cakes.
For the input data:
3 1 2 3 3 2 1
the correct result is:
4
Task author: Anna Zych.
In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.